import { useLocation } from '@/stores/location';
import http from '../utils/request'

export function fetchGoodDetail(id) {
  return http.get('/app-api/cake/product/detail', {
    id: id
  });
}

export function fetchFirstCategory() {
  return http.get('/app-api/cake/product/cats', {
    parent_id: '',
    level: 2,
  });
}
export function fetchCategory(parentId, level) {
  return http.get('/app-api/cake/product/cats', {
    parent_id: parentId,
    level: level,
  });
}
// 获取商品
export function fetchGoodList() {
  const { location } = useLocation()
  return http.get('/app-api/cake/product/list', {
    cityId: location.cityCode
  });
}
// 根据分类获取商品
export function fetchGoodListByCategory(catId2: string, catId3: string) {
  const { location } = useLocation()
  return http.get('/app-api/cake/product/list', {
    catId2: catId2,
    catId3: catId3,
    pageSize: 100,
    cityId: location.cityCode,
  });
}

// 搜索商品
export function fetchSearchGoodList(title: string, pageNo: number, pageSize: number) {
  const { location } = useLocation()
  return http.get('/app-api/cake/product/list', {
    title,
    pageNo,
    pageSize,
    cityId: location.cityCode,
  });
}

